package vis.app.utils;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

import javax.swing.ImageIcon;

public class Utils {
	private static Random rnd = new Random();
	private static BufferedReader br;

	public static ImageIcon createImageIcon(String path) {
		java.net.URL imgURL = Utils.class.getResource(path);
		if (null != imgURL) {
			// System.out.println(imgURL.getPath());
			return new ImageIcon(imgURL);
		} else {
			System.err.println("Couldn't find image: " + path);
			return null;
		}
	}

	public static Color randomColor() {
		int r = rnd.nextInt(255);
		int g = rnd.nextInt(255);
		int b = rnd.nextInt(255);
		return new Color(r, g, b);
	}

	public static Color randomHardColor() {
		int threshold = 200;
		int r = rnd.nextInt(threshold);
		int g = rnd.nextInt(threshold);
		int b = rnd.nextInt(threshold);
		return new Color(r, g, b);
	}

	public static Color inverse(Color color) {
		int r = color.getRed();
		int g = 255 - color.getGreen();
		int b = color.getBlue();
		return new Color(r, g, b);
	}

	public static ArrayList<String> readCodeFile(String path) {
		ArrayList<String> codeText = new ArrayList<String>();
		java.net.URL fileURL = Utils.class.getResource(path);

		try {
			br = new BufferedReader(new FileReader(fileURL.getPath()));
			String line;
			while ((line = br.readLine()) != null) {
				codeText.add(line);
			}
			br.close();

		} catch (IOException e) {
			e.printStackTrace();
		}

		return codeText;
	}

	public static int randomInt(int nMax) {
		return rnd.nextInt(nMax);
	}

	public static void main(String[] args) {
	}
}
